<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');
require_once(JPATH_COMPONENT . DS . 'models' . DS . 'score.php');

class ScorecardViewCourse extends JView {

	function display($tmpl = null) {
		global $option, $mainframe;

		$courseid = JRequest::getVar('courseid', 0, '', 'int');

		// Edit a course
		if ($courseid) {
			$model =& $this->getModel();
			$course = $model->getCourse();
		}

		$model =& JModel::getInstance('score', 'ScorecardModel');
		$country_id = $model->getCountryId() ? $model->getCountryId() : $course['countryid'];
		$state_id = isset($course['stateid']) ? $course['stateid'] : $model->getStateId();
		$status = isset($course['status'])  ? $course['status'] : $model->getStatus();

		$country_list = $model->getCountries();
		$countries = array();
		if (count($country_list) > 0) {
			for ($i = 0, $c = count($country_list); $i < $c; $i++) {
				$countries[] = array('value' => $country_list[$i]->id, 'text' => $country_list[$i]->name);
			}
		}
		$country_select = JHTML::_('select.genericlist', $countries, 'countryid', ' tabindex="6" class="inputbox" onchange="dosubmit(this.form,' . "''" . ')"' . '', 'value', 'text', $country_id);
		$this->assignRef('country', $country_select);

		$state_list = $model->getStates($country_id);
		$states = array();
		if (count($state_list) > 0) {
			for ($i = 0, $c = count($state_list); $i < $c; $i++) {
				$states[] = array('value' => $state_list[$i]->id, 'text' => $state_list[$i]->name);
			}
		}
		$state_select = JHTML::_('select.genericlist', $states, 'stateid', 'tabindex="5" class="inputbox"' . ' ', 'value', 'text', $state_id);
		$this->assignRef('state', $state_select);

		$statuses = array(array('value' => '1', 'text' => 'Active'),array('value' => '0', 'text' => 'Inactive'));
		$status_select = JHTML::_('select.genericlist', $statuses, 'status', 'tabindex="11" class="inputbox"' . ' ', 'value', 'text', $status);
		$this->assignRef('status', $status_select);

		$this->assign('itemid', JRequest::getVar('Itemid'));
		$post = JRequest::get('post');

		if (!$post && $course) {
			$post = $course;
		}
		$this->assignRef('post', $post);
		parent::display($tmpl);
	}
}
?>
